<template>
  <div class="hot-services-management">
    <el-card class="main-card">
      <template #header>
        <div class="card-header">
          <span class="title">热门服务管理</span>
        </div>
      </template>
      
      <el-table :data="servicesList" style="width: 100%" v-loading="loading">
        <el-table-column prop="service_id" label="ID" width="80">
          <template #default="{ row }">
            <span>{{ row.serviceId }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="text" label="服务名称" min-width="200" show-overflow-tooltip />
        <el-table-column prop="image" label="图标" width="120">
          <template #default="{ row }">
            <el-image 
              class="service-image"
              :src="IMAGE_URL + row.image"
              fit="cover"
            />
          </template>
        </el-table-column>
        <el-table-column label="操作" width="120" fixed="right">
          <template #default="{ row }">
            <el-button type="primary" link @click="handleView(row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <!-- 查看详情对话框 -->
    <el-dialog
      v-model="detailVisible"
      title="服务详情"
      width="500px"
      destroy-on-close
      class="service-dialog"
    >
      <div v-if="currentService" class="service-detail">
        <div class="detail-header">
          <h2>{{ currentService.text }}</h2>
        </div>
        <div class="detail-content">
          <div class="detail-section">
            <el-descriptions :column="1" border>
              <el-descriptions-item label="服务ID">{{ currentService.serviceId }}</el-descriptions-item>
              <el-descriptions-item label="服务名称">{{ currentService.text }}</el-descriptions-item>
              <el-descriptions-item label="服务图标">
                <el-image 
                  class="detail-image"
                  :src="IMAGE_URL + currentService.image"
                  fit="cover"
                />
              </el-descriptions-item>
            </el-descriptions>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { getHotServicesList } from '@/api/hotServices'
import { IMAGE_URL } from '@/utils/request'

const loading = ref(false)
const servicesList = ref([])
const detailVisible = ref(false)
const currentService = ref(null)

// 获取服务列表
const getList = async () => {
  loading.value = true
  try {
    const res = await getHotServicesList()
    servicesList.value = res.data
  } catch (error) {
    console.error('获取服务列表失败:', error)
    ElMessage.error('获取服务列表失败')
  } finally {
    loading.value = false
  }
}

// 查看详情
const handleView = (row) => {
  currentService.value = row
  detailVisible.value = true
}

onMounted(() => {
  getList()
})
</script>

<style scoped>
.hot-services-management {
  padding: 20px;
}

.main-card {
  margin-bottom: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.title {
  font-size: 20px;
  font-weight: 600;
  color: #303133;
}

.service-image {
  width: 50px;
  height: 50px;
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.3s;
}

.service-image:hover {
  transform: scale(1.1);
}

.service-detail {
  padding: 20px;
}

.detail-header {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid #ebeef5;
}

.detail-header h2 {
  margin: 0;
  font-size: 24px;
  color: #303133;
}

.detail-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.detail-section {
  background: #f5f7fa;
  padding: 20px;
  border-radius: 8px;
}

.detail-image {
  width: 100px;
  height: 100px;
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.3s;
}

.detail-image:hover {
  transform: scale(1.1);
}

:deep(.el-table) {
  border-radius: 8px;
  overflow: hidden;
}

:deep(.el-table th) {
  background-color: #f5f7fa;
  color: #606266;
  font-weight: 600;
  padding: 12px 0;
}

:deep(.el-table td) {
  padding: 12px 0;
}

:deep(.el-button--link) {
  padding: 0 8px;
  font-size: 13px;
}

:deep(.el-descriptions__label) {
  width: 100px;
  font-weight: 500;
  color: #606266;
}

:deep(.el-descriptions__content) {
  color: #303133;
}

:deep(.el-dialog) {
  border-radius: 8px;
}

:deep(.el-dialog__header) {
  padding: 20px;
  margin: 0;
  border-bottom: 1px solid #ebeef5;
}

:deep(.el-dialog__body) {
  padding: 20px;
}

:deep(.el-dialog__footer) {
  padding: 20px;
  border-top: 1px solid #ebeef5;
}
</style> 